using System.Collections;
using System.Collections.Generic;

namespace HelloWorld.Learn
{
    public class YieldDemo<T> : IEnumerable<T>
    {
        private IList<T> Numbers;
        public YieldDemo(IList<T> nums)
        {
            Numbers = nums;
        }
        
        public IEnumerator<T> GetEnumerator()
        {
            for(int i =0; i < Numbers.Count; i++)
            {
                if (i < 6)
                    yield return Numbers[i];
                else
                    yield break;
            }
            
            yield break;
        }

        IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return GetEnumerator();
        }
    }
}